﻿<style>
body {
	text-align:center;
	margin:0px;
}

#data_manage_edit_content {
	position: absolute;
	z-index: auto;
	height: auto;
	width: 1000px;
	left:0px;
	top:80px;
}
#data_manage_edit_menu {
	width:400px;
	padding-left:20px;
	height:auto;
	text-align:left;
}
#data_manage_edit_top {
	width:900px;
	height:auto;
	margin-top:10px;
	padding-left:50px;
	font-family:"ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size:14px;

}
#data_manage_edit_middle {
	width:900px;
	height:auto;
	margin-top:10px;
	padding-left:50px;

	
}

#data_manage_edit_middle table tr td {
	font-family: "ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size: 14px;
	text-align: center;
}
</style>
	<!--{include /service/service_head}-->
	<div id="data_manage_edit_content">
	<div id="data_manage_edit_menu">
		<ul style="padding-left : 8px, left : 0, ">
			
		</ul>
	</div>
	
	<div id="data_manage_edit_top">
	<form action="/service/dataManageEdit.php" id="indexform" method="post">
			<select name="shop_id" class="f-city">
				<option value="0">選択してください</option>
				${Utility::Option(Utility::OptionArray($shopList, 'id', 'shop_name'), $defaultShopId)}
			</select>
			<select id="staff_id" name="staff_id">
	           	<option value="0">選択してください</option>
				${Utility::Option(Utility::OptionArray($staffList, 'id', 'family_name', 'personal_name'), $staffId)}
	        </select>
	        <select name="time_type" class="f-city">
				<option value="0">選択してください</option>
				${Utility::Option($timeTypeList, $timeType)}
			</select>
			<input type="text" name="start_date" value="${date("Y-m-d", $startTime)}" onfocus="WdatePicker({lang:'jp'})" class="Wdate"/>
			<!--{if $endTime < $startTime}-->
			<input type="text" name="end_date" value="" onfocus="WdatePicker({lang:'jp'})" class="Wdate"/>
			<!--{else}-->
			<input type="text" name="end_date" value="${date("Y-m-d", $endTime)}" onfocus="WdatePicker({lang:'jp'})" class="Wdate"/>
			<!--{/if}-->
		</div>
	
	<div id="data_manage_edit_middle">
	<table width="900" border="1" cellspacing="0" cellpadding="0">
	<tr>
		<td>スタッフ</td><td>トータル出勤時間</td><td>トータル休憩時間</td><td>勤務時間</td>
		<td>時給</td><td>給料合計</td><td>賞用</td><td>交通費</td><td>立替金</td>
		<td>その他</td><td>罰金</td><td>合計</td>
	</tr>
	
    <tr>
    	<?php
			$tempStaff = Staff::getById($one1['staff_id'])
    	?>
    	<td>
    		<input type="hidden" name="id" value="{$one1['id']}"/>
    		<input type="text" id="staff_name" readonly="readonly" value="{$tempStaff['family_name']} {$tempStaff['personal_name']}"/>
    	</td>
    	<td>
    		<input type="text" id="tuukin_total_hour" name="tuukin_total_hour" readonly="readonly" value="{$one1['tuukin_total_hour']}" size="4"/>
    		<input type="text" id="tuukin_total_minute" name="tuukin_total_minute" readonly="readonly" value="{$one1['tuukin_total_minute']}" size="2"/>
    	</td>
    	<td>
    		<input type="text" id="rest_total_hour" name="rest_total_hour" readonly="readonly" value="{$one1['rest_total_hour']}" size="4"/>
    		<input type="text" id="rest_total_minute" name="rest_total_minute" readonly="readonly" value="{$one1['rest_total_minute']}" size="2"/>
    	</td>
    	<td>
    		<input type="text" id="work_total_hour" name="work_total_hour" readonly="readonly" value="{$one1['work_total_hour']}" size="4"/>
    		<input type="text" id="work_total_minute" name="work_total_minute" readonly="readonly" value="{$one1['work_total_minute']}" size="2"/>
    	</td>
    	<td><input type="text" id="salary" name="salary" readonly="readonly" value="{$tempStaff['salary']}" size="4"/></td>
    	<td><input type="text" id="back1" name="back1" value="{$tempStaff['back1']}" size="4"/></td>
    	<td><input type="text" id="reword_money" name="reword_money" value="{$one1['reword_money']}" size="4"/></td>
    	<td><input type="text" id="bus_money" name="bus_money" value="{$one1['bus_money']}" size="4"/></td>
    	<td><input type="text" id="change_money" name="change_money" value="{$one1['change_money']}" size="4"/></td>
    	<td><input type="text" id="other_money" name="other_money" value="{$one1['other_money']}" size="4"/></td>
    	<td><input type="text" id="batu_money" name="batu_money" value="{$one1['batu_money']}" size="4"/></td>
    	<td><input type="text" id="total_money" name="total_money" value="{$one1['total_money']}" size="4"/></td>
    </tr>
	<tr><td><input type="submit" value="作成"></a></td></tr>
  	</table>
    </div>
  	
  	</form>
  <div >
		<a href="{$_SERVER['HTTP_REFERER']}"><font size="+2">戻る</font></a>
	</div>
  	</div>
</body>
</html>
<script type="text/javascript"><!-- 
	var tempCalendar = null;
	jQuery(function(){
		if( $("input[name='start_date']").length > 0 ){
			

			$("select[name='shop_id']").bind("change", function(){
				if( $(this).val() < 1 ){
					return ;
				}
				$.get("{$webRoot}/service/searchStaff.php", "shop_id=" + $(this).val(), function(data){
					
					var options = '<option value="0">選択してください</option>';
					if( data.error == 0 ){
						for(var index in data.data){
							if( !index ){
								continue;
							}
							options = options + '<option value="' + data.data[index].id + '">' + data.data[index].family_name + " " + data.data[index].personal_name + '</option>';
							
						}
					}
					$("#staff_id").html(options);
				}, "json");
				
			});

			$("#staff_id").bind("change", function(){
				calcWorkTime();
				getStaffById();
				
			});

			$("input[name='start_date']").bind("blur", function(e){
				calcWorkTime();
			});

			$("input[name='end_date']").bind("blur", function(e){
				calcWorkTime();
			});

			$("select[name='time_type']").bind("change", function(e){
				calcWorkTime();
			})
		}

		$("#back1").bind("change", function(e){
			calcMoney();
		})

		$("#reword_money").bind("change", function(e){
			calcMoney();
		})

		$("#bus_money").bind("change", function(e){
			calcMoney();
		})

		$("#change_money").bind("change", function(e){
			calcMoney();
		})

		$("#other_money").bind("change", function(e){
			calcMoney();
		})

		$("#batu_money").bind("change", function(e){
			calcMoney();
		})
	});

	function calcWorkTime(){
		$("input[name='end_date']").val( calcEndTime() );
		if( $("#staff_id").val() < 1 || $("input[name='start_date']").val().length < 1 || $("input[name='end_date']").val().length < 1 ){
			return ;
		}
		var data = "staff_id=" + $("#staff_id").val() + "&start_date="+ $("input[name='start_date']").val();
		data = data + "&end_date="+ $("input[name='end_date']").val();
		$.get("{$webRoot}/service/calcWorkTime.php", data, function(data){
			if( data.error == 0 ){
				$("input[name='tuukin_total_hour']").val( data.data.work_schedule_hour );
				$("input[name='tuukin_total_minute']").val( data.data.work_schedule_minute );
				$("input[name='rest_total_hour']").val( data.data.rest_hour);
				$("input[name='rest_total_minute']").val( data.data.rest_minute);
				$("input[name='work_total_hour']").val( data.data.work_hour);
				$("input[name='work_total_minute']").val( data.data.work_minute);
				$("input[name='salary']").val( data.data.salary);
				if( data.data.salary_type < 1 ){
					$("#back1").val( ( data.data.work_hour  + (data.data.work_minute / 60) )* data.data.salary);
				}else if( data.data.salary_type == 1 ){
					var monthPercent = 1;
					$("#back1").val( data.data.salary );
					/*var timeType = $("select[name='time_type']").val();
					if( timeType == 1 ){
						$("#back1").val( data.data.salary / 22 );
					}else if( timeType == 2 ){
						$("#back1").val( data.data.salary / 4 );
					}else{
						$("#back1").val( data.data.salary );
					}*/
										
				}
				calcMoney();
			}
		}, "json");
	}

	function calcMoney(){
		var back1Money = $("#back1").val() * 1;
		var rewordMoney = $("#reword_money").val() * 1;
		var busMoney = $("#bus_money").val() * 1;
		var changeMoney = $("#change_money").val() * 1;
		var otherMoney = $("#other_money").val() * 1;
		var batuMoney = $("#batu_money").val() * 1;
		$("#total_money").val( back1Money + rewordMoney + busMoney + changeMoney + otherMoney - batuMoney );
	}

	function getStaffById(){
		if( $("#staff_id").val() < 1 ){
			return ;
		}
		$.get("{$webRoot}/service/searchStaffById.php", "staff_id=" + $("#staff_id").val(), function(data){
			
			if( data.error == 0 ){
				$("#staff_name").val( data.data['family_name'] + " " + data.data['personal_name'] );
			}
		}, "json");
	}

	/*function  getDaydiff(d1, d2){  
	     var  arrDate,strDate,arrDate2,strDate2,diffDays
	     arrDate= d1.split("-")  
	     strDate=new  Date(arrDate[1]  +  '-'  +  arrDate[2]  +  '-'  +  arrDate[0])    //转换为12-18-2002格式  
	     arrDate2=d2.split("-")  
	     strDate2= new  Date(arrDate2[1]  +  '-'  +  arrDate2[2]  +  '-'  +  arrDate2[0])  
	     diffDays = parseInt(Math.abs(strDate2-strDate)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数  
	     return diffDays; 
	}*/

	function calcEndTime(){
		var strStartDate = $("input[name='start_date']").val();
		if( strStartDate.length < 1 ){
			return "";
		}
		var arrDate= strStartDate.split("-");
		var timeType = $("select[name='time_type']").val();
		if( arrDate.length < 3 || timeType < 1 ){
			return "";
		}
		arrDate[1] = arrDate[1] - 1; 
		var startDate = new Date();
		startDate.setFullYear(arrDate[0], arrDate[1], arrDate[2]);
		var endDate = new Date();
		var timeType = $("select[name='time_type']").val();
		if( timeType == 1 ){
			return strStartDate;
		}else if( timeType == 2 ){
			endDate.setFullYear(arrDate[0], arrDate[1], arrDate[2] * 1 + 6);
		}else if( timeType == 3 ){
			endDate.setFullYear(arrDate[0], arrDate[1]*1 + 1, arrDate[2] - 1);
		}
		return endDate.getFullYear() + "-" + (endDate.getMonth() * 1 + 1) + "-" + endDate.getDate();
	}
</script> 
</html> 